-- ---------------------------
-- 黑名单表
-- ---------------------------
CREATE TABLE IF NOT EXISTS `__PREFIX__fastchat_blacklist` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `user_id` varchar(32) NOT NULL DEFAULT '' COMMENT '用户',
  `session_user_id` varchar(32) NOT NULL DEFAULT '' COMMENT '被屏蔽人',
  `createtime` bigint(16) unsigned DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ---------------------------
-- 消息记录表
-- ---------------------------
CREATE TABLE IF NOT EXISTS `__PREFIX__fastchat_record` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `session_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '会话ID',
  `sender` varchar(32) NOT NULL DEFAULT '' COMMENT '发送人(最终转换为:me=我,you=你)',
  `message` text COMMENT '消息',
  `status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '状态:0=未读,1=已读',
  `createtime` bigint(16) unsigned DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='FastChat消息记录表';

-- ---------------------------
-- 服务账号表
-- ---------------------------
CREATE TABLE IF NOT EXISTS `__PREFIX__fastchat_service_user` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `admin_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '绑定管理员',
  `avatar` varchar(100) NOT NULL DEFAULT '' COMMENT '头像',
  `nickname` varchar(50) NOT NULL DEFAULT '' COMMENT '昵称',
  `add_sessiondata` enum('2','1','0') NOT NULL DEFAULT '0' COMMENT '自动添加会话:0=绑定人在线时添加,1=一律添加,2=不添加',
  `welcome_news` varchar(200) NOT NULL DEFAULT '' COMMENT '欢迎消息',
  `token` varchar(59) NOT NULL DEFAULT '' COMMENT '内部通信身份令牌',
  `online_status` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '在线状态:0=长期在线,1=绑定人在线时',
  `status` enum('1','0') NOT NULL DEFAULT '0' COMMENT '状态:0=关闭,1=启用',
  `createtime` bigint(16) unsigned DEFAULT NULL COMMENT '创建时间',
  `deletetime` bigint(16) unsigned DEFAULT NULL COMMENT '删除时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='FastChat服务账号表';

-- ----------------------------
-- 插入一个服务号
-- ----------------------------
INSERT IGNORE INTO `__PREFIX__fastchat_service_user` VALUES ('1', '', '/assets/addons/fastchat/img/fastchat.png', '我的客服', '1', '终于等到你~~我是【我的客服】服务账号,您可以通过设置绑定人,接受到用户发送给我的消息。', '', '0', '1', '1563860677', null);

-- ---------------------------
-- 游客信息表
-- ---------------------------
CREATE TABLE IF NOT EXISTS `__PREFIX__fastchat_tourists` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `avatar` varchar(100) NOT NULL DEFAULT '' COMMENT '头像',
  `nickname` varchar(50) NOT NULL DEFAULT '' COMMENT '昵称',
  `token` varchar(59) NOT NULL DEFAULT '' COMMENT 'Session标识',
  `createtime` bigint(16) unsigned DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='FastChat游客信息表';

-- ---------------------------
-- 会话表
-- ---------------------------
CREATE TABLE IF NOT EXISTS `__PREFIX__fastchat_session` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `user_id` varchar(32) NOT NULL DEFAULT '0' COMMENT '用户',
  `session_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '会话类型:0=与普通用户,1=与管理员,2=游客,3=未知(无身份标识),4=未知用户,5=服务账号',
  `session_user_id` int(11) NOT NULL DEFAULT '0' COMMENT '会话对象',
  `createtime` bigint(16) unsigned DEFAULT NULL COMMENT '创建时间',
  `deletetime` bigint(16) unsigned DEFAULT NULL COMMENT '删除时间',
  `deleteuser` varchar(32) NOT NULL DEFAULT '' COMMENT '此用户单方删除会话',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='FastChat会话表';

-- ----------------------------
-- v1.0.6
-- ----------------------------
BEGIN;
ALTER TABLE `__PREFIX__fastchat_blacklist` MODIFY COLUMN `createtime` bigint(16) UNSIGNED NULL DEFAULT NULL COMMENT '创建时间';
ALTER TABLE `__PREFIX__fastchat_record` MODIFY COLUMN `createtime` bigint(16) UNSIGNED NULL DEFAULT NULL COMMENT '创建时间';
ALTER TABLE `__PREFIX__fastchat_service_user` MODIFY COLUMN `createtime` bigint(16) UNSIGNED NULL DEFAULT NULL COMMENT '创建时间';
ALTER TABLE `__PREFIX__fastchat_service_user` MODIFY COLUMN `deletetime` bigint(16) UNSIGNED NULL DEFAULT NULL COMMENT '删除时间';
ALTER TABLE `__PREFIX__fastchat_tourists` MODIFY COLUMN `createtime` bigint(16) UNSIGNED NULL DEFAULT NULL COMMENT '创建时间';
ALTER TABLE `__PREFIX__fastchat_session` MODIFY COLUMN `createtime` bigint(16) UNSIGNED NULL DEFAULT NULL COMMENT '创建时间';
ALTER TABLE `__PREFIX__fastchat_session` MODIFY COLUMN `deletetime` bigint(16) UNSIGNED NULL DEFAULT NULL COMMENT '删除时间';
COMMIT;